﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ThietBiSo.Helper
{
    public class StringUtil
    {
        public static string ConvertStringToDate(string date)
        {
            char[] splitter = {'/'}; 

            if (String.IsNullOrEmpty(date) || date == "") return null; 
           
            string[] splitDate = date.Split(splitter);

            if (splitDate.Length != 3) return null;

            return splitDate[1] +"/" +splitDate[0] +"/"+ splitDate[2];
             
        }
        /// <summary>
        ///     /// convert dd/mm/yyyy -> mm/dd/yyyy
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string ConvertStringToDatePadLeft(string date)
        {
            char[] splitter = { '/' };

            if (String.IsNullOrEmpty(date) || date == "") return null;

            string[] splitDate = date.Split(splitter);

            if (splitDate.Length != 3) return null;
            //Edit by an.le 21/06/2010
            //return splitDate[1] + "/" + splitDate[0] + "/" + splitDate[2];
            return splitDate[1].PadLeft(2, '0') + "/" + splitDate[0].PadLeft(2, '0') + "/" + splitDate[2];

        }
      
    }
}
